package cn.hyy.FVOnline.mapper;

import cn.hyy.FVOnline.entity.Shop;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("shopMapper")
public interface ShopMapper {

    @Results(id = "shopMap",value = {
        @Result(property = "id", column = "id",id = true),
        @Result(property = "shopname", column = "shopname"),
        @Result(property = "hsPath", column = "hspath"),
        @Result(property = "userId", column = "userid"),
        @Result(property = "goodsnum", column = "goodsnum"),
        @Result(property = "sellnum", column = "sellnum"),
        @Result(property = "reason", column = "reason"),
        @Result(property = "state", column = "state")
    })
    @Select("select * from shop where userid = #{shop.userId}")
    Shop findByUserId(@Param("shop") Shop shop);

    @Insert("insert into shop (shopname, hspath, userid, reason) values (#{shop.shopname},#{shop.hsPath},#{shop.userId},#{shop.reason})")
    void newShop(@Param("shop") Shop shop);

    @Select("select * from shop where id = #{id}")
    Shop findById(@Param("id") Integer id);

    @Select("select * from shop where shopname like #{name} and state = 1 limit #{start}, #{pageSize}")
    List<Shop> findPageShopList(@Param("name")String name, @Param("start") Integer start, @Param("pageSize")Integer pageSize);

    @Select("select count(*) from shop where shopname like #{name} and state = 1")
    Integer findSearchTotal(@Param("name")String name);

    @Update("update shop set state = 2 where id = #{id}")
    void delShop(@Param("id")Integer id);

    @Select("select * from shop where state = 0 limit #{start}, #{pageSize}")
    List<Shop> findPageShopList2(@Param("start") Integer start, @Param("pageSize")Integer pageSize);

    @Select("select count(*) from shop where state = 0")
    Integer findSearchTotal2();

    @Update("update shop set state = 1 where id = #{id}")
    void addShop(@Param("id")Integer id);

    @Update("update shop set sellnum = sellnum + #{sell} where id = #{id}")
    void addSell(@Param("sell")Integer sell,@Param("id")Integer id);

    @Update("update shop set goodsnum = goodsnum + 1 where id = #{id}")
    void addGoods(@Param("id")Integer id);
}
